//
// Created by 86150 on 2021/10/14.
//
#ifndef BJUT_CPP3_CCOMPLEX_H
#define BJUT_CPP3_CCOMPLEX_H

class CComplex
{
	private:
		double real;
		double imag;

	public:
		CComplex(double re=0, double im = 0): real(re), imag(im) {}
		CComplex operator+ (CComplex& other)
		{
			return CComplex(real + other.real, imag + other.imag);
		}
		CComplex operator- (CComplex& other)
		{
			return CComplex(real - other.real, imag - other.imag);
		}
		CComplex operator* (CComplex& other)
		{
			double new_real = real * other.real - imag * other.imag;
			double new_imag = real * other.imag - imag * other.real;
			return CComplex(new_real, new_imag);
		}
		CComplex operator/ (CComplex& other)
		{
			double new_real = (real * other.real + imag * other.imag) /
					(other.real * other.real + other.imag * other.imag);
			double new_imag = (imag * other.real - real * other.imag) /
					(other.real * other.real + other.imag * other.imag);
			return CComplex(new_real, new_imag);
		}
		CComplex operator++ ()
		{
			return CComplex(real + 1, imag + 1);
		}
		CComplex operator++ (int)
		{
			return CComplex(real + 1, imag + 1);
		}
		void operator= (CComplex& other)
		{
			real = other.real;
			imag = other.imag;
		}
		friend std::ostream& operator<<(std::ostream& cout, CComplex now)
		{
			cout<<now.real<<" + "<<now.imag<<"i";
			return cout;
		}
		friend void operator<< (std::string& str, CComplex now)
		{
			str = std::to_string(now.real) + " + " + std::to_string(now.imag) + "i";
		}
};
#endif //BJUT_CPP3_CCOMPLEX_H
